#include<bits/stdc++.h>
using namespace std;
int t,n,a[200005],ans;
bool color[200005];
void dfs(int x){
    if(x==n+1){
        int cnt = 0;
        for(int i = 2;i<=n;i++){
            int j = i-1;
            while(color[j]!=color[i])j--;
            if(a[i]==a[j])cnt+=a[i];
        }
        ans = max(cnt,ans);
        return;
    }
    color[x]=false;
    dfs(x+1);
    color[x]=true;
    dfs(x+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i = 1;i<=n;i++){
            cin>>a[i];
        }
        dfs(1);
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

